<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus';

defineProps({
  msg: String,
})

const count = ref(0)

function getData() {
  let obj = javaConnector.toLowerCase("1b")
  ElMessage('这是一条消息' + obj.toString());
}

function sayHello(val) {
  ElMessage('这是一条消息22' + val);
}

let jsConnector = {
  showResult: function (result) {
    ElMessage('结果显示: ' + result);
  }
}

function getJsConnector() {
  return jsConnector;
}

function handleFileChange(event) {
  const file = event.target.files[0];
  if (file) {
    sendFileToJavaFX(file);
  }
}
function sendFileToJavaFX(file) {
  // 将文件对象转换为 Base64 编码的字符串
  ElMessage('上传: ' + file.name);
  const reader = new FileReader();
  reader.onloadend = () => {
    const base64String = reader.result.split(',')[1];
    ElMessage('上传1: ' + base64String);
    javaConnector.saveFile(base64String, file.name);
  };
  reader.readAsDataURL(file);
}

// 暴露方法给全局对象
window.getJsConnector = () => jsConnector;

// 将方法暴露给全局对象
window.sayHelloFromVue = sayHello;
</script>

<template>
  <div class="container">
    <h1>{{ msg }}</h1>

    <div class="card">
      <button type="button" @click="count++">count is {{ count }}</button>
      <button type="button" @click="getData">请求后台数据</button>
      <input type="file" @change="handleFileChange" />
      <p></p>
      <p>Edit <code>components/HelloWorld.vue</code> to test HMR</p>
    </div>

    <p>
      Check out
      <a href="https://vuejs.org/guide/quick-start.html#local" target="_blank">create-vue</a>,
      the official Vue + Vite starter
    </p>
    <p>
      Learn more about IDE Support for Vue in the
      <a href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support" target="_blank">Vue Docs Scaling up Guide</a>.
    </p>
    <p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
  </div>
</template>

<style scoped>
.container {
  background-color: #ffffff; /* 白色背景 */
  padding: 20px;
}

.read-the-docs {
  color: #fcfcfc;
}
</style>

